package com.drama.api.sys.company.controller;

import com.drama.api.base.ApiIndex;
import com.drama.api.base.Constants;
import com.drama.api.base.R;
import com.drama.api.base.RestPage;
import com.drama.api.sys.company.domain.vo.*;
import com.drama.api.sys.company.service.ISysCompanyService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.SysCompanyController)
@RequestMapping(value = "/api/sys/company")
@RestController
public class SysCompanyController {

    @Autowired
    private ISysCompanyService service;

    @ApiOperation(value = "查询商户集合")
    @GetMapping(value = "/list")
    public R<RestPage<List<SysCompanyVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute SysCompanySearchVO searchVO) {
        List<SysCompanyVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }



    @ApiOperation(value = "测试创建商户")
    @PostMapping(value = "/createList")
    public R createList() {
        for (int i = 1; i <= 50; i++) {
            SysCompanyAddVO sysCompanyAddVO=new SysCompanyAddVO();
            sysCompanyAddVO.setCompanyName("测试商户【"+i+"】");
            sysCompanyAddVO.setCompanyAccount("cheshi_"+i);
            sysCompanyAddVO.setCompanyImg("http://api-file.yujuyi.com/file/999999/2023/1218/1736608509588594688.jpg");
            sysCompanyAddVO.setCompanyReferred("测试商户【"+i+"】");
            sysCompanyAddVO.setCompanyPassword("E10ADC3949BA59ABBE56E057F20F883E");
            sysCompanyAddVO.setCompanyAddr("测试地址");
            sysCompanyAddVO.setCompanyPhone("18699999999");
            sysCompanyAddVO.setCompanyEmail("18699999999@163.com");
            sysCompanyAddVO.setCompanyContacts("测试");
            sysCompanyAddVO.setCompanyType(1);
            sysCompanyAddVO.setCovenantUrl("http://api-file.yujuyi.com/file/999999/2023/1218/1736608488298307584.jpg");
            service.add(sysCompanyAddVO);
        }
        return new R();
    }
    @ApiOperation(value = "创建商户信息")
    @PostMapping(value = "/add")
    public R create(@ApiParam(value = "添加参数") @Valid @RequestBody SysCompanyAddVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.add(vo);
        }
        return result;
    }

    @ApiOperation(value = "修改商户信息")
    @PostMapping(value = "/update")
    public R update(@ApiParam(value = "添加参数") @Valid @RequestBody SysCompanyUpdateVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.update(vo);
        }
        return result;
    }

    @ApiOperation(value = "重置商户密码")
    @PostMapping(value = "/reset_password")
    public R reset_password(@ApiParam(value = "添加参数") @Valid @RequestBody SysCompanyResetPasswordVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.resetPassword(vo);
        }
        return result;
    }


    @ApiOperation(value = "是否允许商户登录")
    @PostMapping(value = "/is_login")
    public R is_login(@ApiParam(value = "参数") @Valid @RequestBody SysCompanyAuthorityVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.isLogin(vo);
        }
        return result;
    }
    @ApiOperation(value = "是否允许商户上传视频")
    @PostMapping(value = "/is_upload")
    public R is_upload(@ApiParam(value = "参数") @Valid @RequestBody SysCompanyAuthorityVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.isUpload(vo);
        }
        return result;
    }
    @ApiOperation(value = "是否允许商户提审")
    @PostMapping(value = "/is_arraign")
    public R is_arraign(@ApiParam(value = "参数") @Valid @RequestBody SysCompanyAuthorityVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.isArraign(vo);
        }
        return result;
    }
    @ApiOperation(value = "是否允许商户提现")
    @PostMapping(value = "/is_withdraw")
    public R is_withdraw(@ApiParam(value = "参数") @Valid @RequestBody SysCompanyAuthorityVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.isWithdraw(vo);
        }
        return result;
    }



}
